package com.ebraga.trackerclub.android.util.core;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.ebraga.trackerclub.android.util.api.AndroidContentValues;
import com.ebraga.trackerclub.android.util.api.AndroidSQLiteDatabase;

public class AndroidSQLiteDatabaseImpl implements AndroidSQLiteDatabase {
	
	SQLiteDatabase db;

	@Override
	public Cursor query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy) {
		return db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy);
	}
	
	@Override
	public Cursor query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit) {
		return db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy, limit);
	}	

	@Override
	public Long insert(String table, AndroidContentValues val) {
		return db.insertOrThrow(table, null, val.getContentValues());
	}
	
	@Override
	public Long update(String table, AndroidContentValues values, String whereClause, String[] whereArgs) {
		return (long) db.update(table, values.getContentValues(), whereClause, whereArgs);
	}	

	@Override
	public int delete(String table, String whereClause, String[] whereArgs) {
		return (int) db.delete(table, whereClause, whereArgs);
	}

	@Override
	public boolean isOpen() {
		return db.isOpen();
	}

	@Override
	public void close() {
		db.close();
		
	}

	@Override
	public Cursor rawQuery(String sql, String[] selectionArgs) {
		return db.rawQuery(sql, selectionArgs);
	}

	@Override
	public void setSQLLiteDataBase(SQLiteDatabase database) {
		this.db=database;
		
	}

	@Override
	public void beginTransaction() {
		db.beginTransaction();		
	}

	@Override
	public void endTransaction() {
		db.endTransaction();		
	}

	@Override
	public void setTransactionSuccessful() {
		db.setTransactionSuccessful();		
	}

}
